package com.myProject.serves.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myProject.bean.TArea;
import com.myProject.dao.AreaDao;
import com.myProject.serves.AreaSev;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

import java.util.List;

public class AreaSevImpl implements AreaSev {
    @Override
    public List<TArea> getAreaList(TArea tArea) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        AreaDao ad = sqlSession.getMapper(AreaDao.class);
        List<TArea>list = ad.getAreaList(tArea);
        sqlSession.clearCache();
        return list;
    }

    @Override
    public PageInfo<TArea> showAreaByPage(int pageNo, int pageSize, TArea tArea) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        AreaDao ad = sqlSession.getMapper(AreaDao.class);
        PageHelper.startPage(pageNo,pageSize);
        List<TArea>list = ad.getAreaList(tArea);
        PageInfo<TArea>page = new PageInfo<TArea>(list);
        SqlSessionUtil.commit();
        return page;
    }

    @Override
    public void addArea(TArea tArea) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        AreaDao ad = sqlSession.getMapper(AreaDao.class);
        int x = ad.addArea(tArea);
        SqlSessionUtil.commit();
        sqlSession.close();
    }

    @Override
    public List<TArea> findNoClass() {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        AreaDao ad = sqlSession.getMapper(AreaDao.class);
        List<TArea>list = ad.findNoClass();
        System.out.println("findNoclass = " + list);
        sqlSession.clearCache();
        return list;
    }

    @Override
    public void updateArea(TArea tArea) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        AreaDao ad = sqlSession.getMapper(AreaDao.class);
        int x = ad.updateArea(tArea);
        SqlSessionUtil.commit();
        sqlSession.close();
    }
}
